require(['select2', 'date','validator','jquery-form'], function() {
	var $formData = $('#formData'),$carModel = $('#carModel');
	$formData.initForm();
	$carModel.html("");
	$.ajaxExt({
		url : "/upgrade/getCarModel.htm"
	}).done(function(data) {
		var carInfoList = data;
		var optionH = "";
		$.each(carInfoList, function (n, carInfo) {
			optionH = optionH + "<option value='" + carInfo.carModel + "'>" + carInfo.carModel + "</option>";
		});
		$carModel.append(optionH);
        var userInfo = commonFun.execParentMethod("getUserInfo");
        // console.info(userInfo);
        $("#upgradeUser").val(userInfo.name);
        var myDate = new Date();
        $("#upgradeDate").val(myDate.toLocaleString( ));
	});

	add = function(fn) {
		addOrUpdate("/upgrade/addAppMgr.htm",fn);
	};

	function addOrUpdate(url,callBack){
		var result = $.validator($formData);
		if(result){
			var $mask;
			$mask = $.createMask(window.parent.document.body);  //遮罩
			$formData.ajaxSubmit({
				dataType : 'JSON',
				success : function(result){
					$mask.remove();
					if (result && result.msgType) {
						if (result.msgType && result.msgType == '2') {
							$.messager.alert("警告", result.msg || "系统异常", "warning");
						} else if (result.msgType && result.msgType == '3') {
							$.messager.alert("错误", result.msg || "系统异常", "error");
						}else if (result.msgType && result.msgType == '1') {
							$.messager.alert("提示", result.msg , "info");
							callBack()
						}
					}else{
						callBack()
					}
				},
				error : function() {
					$mask.remove();
					$.messager.alert("错误", "系统异常", "error");
				}
			});
		}
	}
});